package informationGet.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;


import com.whu.zj.MyApplication;
import com.whu.zj.R;

import java.util.ArrayList;
import java.util.List;

import informationGet.dto.PointXY;


/**
 * Created by 凯 on 2015/11/25.
 */
public class PickPointsAdatper extends BaseAdapter {

    // 保存采集的经纬度
    List<ItemClass> pointXYs = new ArrayList<ItemClass>();

    public List<ItemClass> getPointXYs() {
        return pointXYs;
    }

    public void setPointXYs(List<ItemClass> pointXYs) {
        this.pointXYs = pointXYs;
    }

    @Override
    public int getCount() {
        return pointXYs.size();
    }

    @Override
    public Object getItem(int position) {
        return pointXYs.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ItemClass itemClass = pointXYs.get(position);
        convertView = View.inflate(MyApplication.share(), R.layout.item_points,null);


        TextView tv_jingdu = (TextView) convertView.findViewById(R.id.id_tv_jingdu);
        TextView tv_weidu = (TextView) convertView.findViewById(R.id.id_tv_weidu);
        CheckBox cb_choose = (CheckBox) convertView.findViewById(R.id.id_cb_choose);

        tv_jingdu.setText(itemClass.getPointXY().getX()+"");
        tv_weidu.setText(itemClass.getPointXY().getY()+"");
        cb_choose.setChecked(itemClass.isChoosed);
        cb_choose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                itemClass.setIsChoosed(isChecked);
            }
        });

        return convertView;
    }


    // 数据
    public static class ItemClass
    {
        PointXY pointXY = new PointXY();
        boolean isChoosed = false;

        public PointXY getPointXY() {
            return pointXY;
        }

        public void setPointXY(PointXY pointXY) {
            this.pointXY = pointXY;
        }

        public boolean isChoosed() {
            return isChoosed;
        }

        public void setIsChoosed(boolean isChoosed) {
            this.isChoosed = isChoosed;
        }
    }

}
